package com.example.mkio.androidpractice;

import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.NotificationCompat;
import android.view.View;
import android.widget.Button;
import android.widget.RemoteViews;

import com.example.mkio.androidpractice.webview.WebviewJsActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    static {
        System.loadLibrary("native-lib");
    }
    public native String stringFromJNI();

    private Button notice;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        notice = (Button) findViewById(R.id.btn_notice);
        notice.setOnClickListener(this);
        findViewById(R.id.btn_notice).setOnClickListener(this);
        findViewById(R.id.btn_notice_Default).setOnClickListener(this);
        findViewById(R.id.btn_notice_remote_view).setOnClickListener(this);
        findViewById(R.id.btn_group_view).setOnClickListener(this);
        findViewById(R.id.btn_group_view_js).setOnClickListener(this);
        findViewById(R.id.btn_view_pager).setOnClickListener(this);

//        TextView tv = (TextView) findViewById(R.id.sample_text);
//        tv.setText(stringFromJNI());
    }


    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    @Override
    public void onClick(View v) {
        switch (v.getId()) {

            case R.id.btn_notice_remote_view:
                NotificationManager mRemoteViewManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
                PendingIntent p = PendingIntent.getActivities(this, 0, new Intent[]{new Intent(this, TakePhotoActivity.class)}, 0);
                RemoteViews mRemoteViews = new RemoteViews(getPackageName(), R.layout.notification_upload);
                mRemoteViews.setOnClickPendingIntent(R.id.tv_continue, p);
                mRemoteViews.setTextViewText(R.id.tv_notification, "remoteviews");
                builder.setContent(mRemoteViews);
                Notification mNotification = builder.build();
                mRemoteViewManager.notify(2, mNotification);
                break;

            case R.id.btn_notice_Default:
                NotificationManager mManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                Intent intent = new Intent(this, TakePhotoActivity.class);
                PendingIntent pendingIntent = PendingIntent.getActivities(this, 0, new Intent[]{intent}, PendingIntent.FLAG_UPDATE_CURRENT);
                Notification mNotice = new Notification.Builder(this)
                        .setContentText("123")
                        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                        .setSmallIcon(R.mipmap.ic_launcher)
                        .setAutoCancel(true)
                        .setContentIntent(pendingIntent)
                        .setWhen(System.currentTimeMillis())
                        .build();
                mManager.notify(1, mNotice);
                break;
            case R.id.btn_notice:
                startActivity(new Intent(this, TakePhotoActivity.class));
                break;

            case R.id.btn_group_view:
                startActivity(new Intent(this,ViewGroupActivity.class));
                break;

            case R.id.btn_group_view_js:
                startActivity(new Intent(this,WebviewJsActivity.class));
                break;

            case R.id.btn_view_pager:
                startActivity(new Intent(this,WeiBoActivity.class));
                break;



        }

    }
}
